﻿
@model YouWei.Infrastructure.Entity.WashShop

@{

    ViewBag.Title = "文章发布(公众号)";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        洗车店铺管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">洗车店铺管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="box box-primary">
            <div class="box-body">
                <div class="form-group">
                    <label for="commentName">洗车店名称</label>
                    <input type="text" class="form-control" id="commentName" maxlength="50" value="@Model.WashName">
                </div>
                <div class="form-group">
                    <label for="commentName">详细地址</label>
                    <input type="text" class="form-control" id="address" maxlength="50" value="@Model.Address">
                </div>
                <div class="form-group">
                    <label for="commentName">工作时间</label>
                    <input type="text" class="form-control" id="workTime" value="@Model.WorkTime">
                </div>
                <div data-toggle="distpicker" class="form-group">
                    <label>所在地</label>
                    <div>
                        <select style="width: 10%; display: inline-block;" name="HProince" id="HProince" class="form-control"></select>
                        <select style="width: 10%; display: inline-block;" name="HCity" id="HCity" class="form-control"></select>
                        <select style="width: 10%; display: inline-block;" name="HDis" id="HDis" class="form-control"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="commentDesc">图片</label>
                    <div class="form-control" style="border-width:0px;">
                        <div id="HeadImageUrl" class="col-sm-10 dm-uploader">
                            <div role="button" class="btn btn-primary mr-2">
                                <i class="fa fa-fw fa-folder-o"></i>图片上传
                                <input type="file" title="Click to add Files">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="over-hidden" style="">
                        <div id="divImg" class="img-wrapper-titlephoto fl" style="display: none;">
                            <img id="imgPhoto" style="width: 360px; height: 160px;border:1px solid #ccc " />
                            <input type="hidden" id="hidDbUrl" />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="commentName">地理经度（点击弹出地图）</label>
                    <input type="text" class="form-control" id="txtLongitude" onclick="GetMap()" value="@Model.Longitude">
                </div>
                <div class="form-group">
                    <label for="commentName">地理纬度</label>
                    <input type="text" class="form-control" id="txtLatitude" value="@Model.Latitude">
                </div>
                <div class="form-group">
                    <input type="button" style="width:15%" class="btn btn-primary" id="save" value="保存" />
                </div>
            </div>
        </div>

    </div>
</section>
@section scriptsBottom{
    <script type="text/javascript">
        $(function () {
            var headImgUrl = "@ViewBag.ImageUrl" || "";
            if (headImgUrl != "") {
                $("#imgPhoto").attr("src", headImgUrl);
                $("#hidDbUrl").val(headImgUrl);//存数据库里的相对路径
                $("#divImg").show();
            }

            var pid = "@Model.ProvinceID";
            var cid = "@Model.CityID";
            var did = "@Model.DistrictID";
            $("#HProince").val(pid);
            $("#HProince").change();
            $("#HCity").val(cid),
            $("#HCity").change(),
            $("#HDis").val(did)
            renderImg();
            binds();
        });
        function binds() {
            $("#save").on("click", function () {
                save();
            });
        }
        //获取坐标
        function GetMap() {
            var name = $("#address").val();
            showLayer("获取坐标", "@Url.Action("Map", "Public")?name=" + escape(name), 650, 550);
        }

        function SetLocation(lon, lat) {
            $("#txtLongitude").val(lon);
            $("#txtLatitude").val(lat);
        }

        function save() {

            var data = {
                WashName: $("#commentName").val(),
                Address: $("#address").val(),
                WorkTime: $("#workTime").val(),
                Longitude: $("#txtLongitude").val(),
                Latitude: $("#txtLatitude").val(),
                ImageUrl: $("#hidDbUrl").val() || "",
                ProvinceID: $("#HProince").val(),
                CityID: $("#HCity").val(),
                DistrictID: $("#HDis").val()
            };
            console.log(data);
            var url = "@Url.Action("WashShopSave", "Public")?id=@ViewBag.WashShopID";
            BMCW.ajax({
                url: url,
                type: 'POST',
                data: data,
                success: function (res) {
                    if (res.status == 0) {
                        //草稿留在当前页
                        if (data.isShow == 0) {
                            BMCW.alert("保存草稿成功");
                        } else {
                            BMCW.alert("发布成功");
                            window.location.href = "@Url.Action("WashShopIndex", "Public")";
                        }
                    } else {
                        BMCW.alert(res.message);
                    }
                }
            });
        }
         function renderImg() {
            $('#HeadImageUrl').dmUploader({ //
                url: '@Url.Action("UploadImg", "Product")',
                maxFileSize: 3000000, // 3 Megs max
                multiple: false,
                allowedTypes: 'image/*',
                extFilter: ['jpg', 'jpeg', 'png', 'gif'],
                onUploadSuccess: function (id, response) {
                    if (response.status==0) {
                        var oData = response.data;
                        $("#imgPhoto").attr("src",oData.HttpImgUrl);
                        $("#hidDbUrl").val(oData.ImgUrl);//存数据库里的相对路径
                        $("#divImg").show();
                        $("#hidImgPhoto-error").remove();
                    } else {
                        alert(response.data.message);
                    }
                }
            });
        }
        //弹出一个窗口
        function showLayer(titleName, url, mwidth, mheight, otherOpts) {
            mwidth = mwidth || 900;
            //mwidth = Math.max(mwidth, 400);
            mheight = mheight || 550;
            //mheight = Math.max(mheight, 350);
            var settings = {
                type: 2,
                title: titleName,
                maxmin: true,
                //shadeClose: true, //点击遮罩关闭层
                area: [mwidth + 'px', mheight + 'px'],
                content: [url], //[url,'no']
                resize: true //是否允许拉伸
            };
            if (otherOpts && $.isPlainObject(otherOpts)) {
                settings = $.extend(settings, otherOpts);
            }
            var index = layer.open(settings);
            window.currentLayerIndex = index;
            return index;
        }
    </script>

}